﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;


namespace PlatWL.Data
{
    public interface IBaseDao<T> where T : class //限制class
    {
        #region 查询普通实现方案(基于Lambda表达式的Where查询)

        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        int GetCount(Func<T, bool> exp);

        /// <summary>
        /// 获取所有Entity
        /// </summary>
        /// <param name="exp">Lambda条件的where</param>
        /// <returns></returns>
        IEnumerable<T> GetEntities(Expression<Func<T, bool>> exp);


        /// <summary>
        /// 根据条件查找
        /// </summary>
        /// <param name="exp">lambda查询条件where</param>
        /// <returns></returns>
        T GetEntity(Expression<Func<T, bool>> exp);

        T GetEntityFirst(Expression<Func<T, bool>> exp);

        #endregion 查询普通实现方案(基于Lambda表达式的Where查询)

        ///// <summary>
        ///// 获取所有Entity(立即执行请使用ToList()
        ///// </summary>
        ///// <param name="CommandText">Sql语句</param>
        ///// <param name="objParams">可变参数</param>
        ///// <returns></returns>
        //IEnumerable<T> GetEntities(string CommandText);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        IQueryable<T> GetEntities(Func<T, bool> whereLambda, Func<T, dynamic> orderLambda, string sortOrder, int pageIndex, int pageSize, out int totalCount);


        /// <summary>
        /// 插入Entity
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Insert(T entity);

        /// <summary>
        /// 插入多个实体
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        bool Insert(IEnumerable<T> entities);

        /// <summary>
        /// 更新Entity
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Update(T entity);

        /// <summary>
        /// 删除Entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Delete(T entity);

        /// <summary>
        /// 根据条件删除
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        bool Delete(Func<T, bool> whereLambda);
    }
}